package z_exam;

import java.util.*;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/16 22:36
 */
public class test1 {
    public static void main(String[] args) {
        Map<Integer, Integer> hash = new HashMap<>();
        //初始化容量
        int initialCapacity = 10;
        //加载因子，一般是 0.75f
        float loadFactor = 0.75f;
        //排序方式 false 基于插入顺序  true  基于访问顺序
        boolean accessOrder = true;
        LinkedHashMap<String, Integer> map = new LinkedHashMap(initialCapacity, loadFactor, accessOrder){
            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return size() > initialCapacity;
            }

        };
        map.size();
        for (int i = 0; i < 10; i++) {
            map.put(String.valueOf(i), i);
        }
        //访问前顺序
        Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next().getKey());
        }
//        map.remove("5");
        map.put("51", 1);
        map.put("5", 1);
//        map.get("5");
        //模拟访问
//        map.get("5");
        System.out.println();
        System.out.println();
        System.out.println();
        //访问后数据
        //访问前顺序
        Iterator<Map.Entry<String, Integer>> iterator1 = map.entrySet().iterator();
        while(iterator1.hasNext()){
            System.out.println(iterator1.next().getKey());
        }
    }
}
